package org.springcloud.wisdom.spring_02_classroom.teacher.tschedule.controller;

import org.springcloud.wisdom.spring_02_classroom.bean.BaseController;
import org.springcloud.wisdom.spring_02_classroom.bean.ResponseData;
import org.springcloud.wisdom.spring_02_classroom.student.sschedule.entity.Student;
import org.springcloud.wisdom.spring_02_classroom.teacher.tschedule.service.TeacherScheduleService;
import org.springcloud.wisdom.spring_02_classroom.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.http.WebSocket;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/tselect")
public class TeacherScheduleController extends BaseController {
    @Autowired
    private TeacherScheduleService teacherScheduleService;
    @Autowired
    private WebSocketServer webSocketServer;

    //教师查看自己名下的课程
    @GetMapping("/selfcourse")
    public ResponseData<Object> getCoursesByTeacherId(String tid) {
        return returnObject(teacherScheduleService.findCoursesByTid(tid));
    }

    //教师查看所属课程的学生
    @GetMapping("/selfstudent")
    public ResponseData<Object> getStudentsByTid(String tid,String cid) {
        return returnObject(teacherScheduleService.getStudentsByTid(tid, cid));
    }

    // 教师随机选择一个学生
    @GetMapping("/random")
    public ResponseData<Object> getRandomStudent(@RequestParam String tid, @RequestParam String cid) {
        List<Student> students = teacherScheduleService.getStudentsByTid(tid, cid);
        Student randomStudent = teacherScheduleService.getRandomStudent(students);
        if (randomStudent == null) {
            return returnObject("No students available for random selection.");
        }
        return returnObject(randomStudent);
    }

    //历史课程
    @RequestMapping("/all")
    public ResponseData<Object> getPage(@RequestParam("pageNum") int pageNum,
                                        @RequestParam("pageSize") int pageSize,
                                        @RequestParam(value = "tid",required = false) String tid){
        return returnObject(teacherScheduleService.getcoursehistory(pageNum,pageSize,tid));
    }
}
